<template>
	<view class="work-container">
		<!-- <z-paging ref="paging" v-model="dataList" @query="queryList"> -->
		<view class="noData" v-if="dataList.length == 0">
			暂无数据
		</view>
		<scroll-view class="scroll-view_H" v-if="dataList.length > 0" scroll-y="true" @scroll="scroll">
			<view class="item flex align-center p-t-5 p-b-5" v-for="(item,index) in dataList" :key="index"
				@click="toDoctorDetail(item)">
				<u--image width="70" height="70"
					:src="item.doctorImg?item.doctorImg:item.sex=='2'?require('@/static/images/homeIndex/doct-g.png'):item.sex=='1'?require('@/static/images/homeIndex/doct-m.png'):require('@/static/images/homeIndex/avator-doctor.png')"
					shape="circle"></u--image>
				<view style="height: 100%;flex: 1;" class="flex flex-column justify-around p-l-16 p-t-10 p-b-10">
					<view class="flex align-center justify-between m-b-10">
						<view class="flex align-center">
							<text style="font-size: 32rpx;color: #323232;" class="m-r-20">{{item.doctorName}}</text>
							<text style="font-size: 32rpx;color: #323232;">{{item.deptName}}</text>
						</view>
						<img style="width: 40rpx;" src="@/static/images/arrow-right.svg" alt="">
					</view>
					<text class="overEllips" style="font-size: 26rpx;color: #999999;">{{item.articleTitle}}</text>
				</view>
			</view>

		</scroll-view>

		<!-- </z-paging> -->
	</view>
</template>

<script>
	import config from "@/config.js";
	import {
		getDoctorList
	} from "@/api/home/home.js";
	export default {
		props: {
			deptCode: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				dataList: [],
				hospitalCode: ''
			}
		},
		created() {
			let hosCode = uni.getStorageSync('hospital') || ''
			this.hospitalCode = JSON.parse(hosCode).hospitalCode
			this.getData()
		},
		onLoad: function() {
			let hosCode = uni.getStorageSync('hospital') || ''
			this.hospitalCode = JSON.parse(hosCode).hospitalCode
			this.getData()
		},
		onPullDownRefresh() {
			this.getData()
		},
		methods: {
			toDoctorDetail(res) {
				uni.navigateTo({
					url: '/pages/home/doctorDetail?id=' + res.id
				})
			},
			getData() {
				getDoctorList({
					hospitalCode: this.hospitalCode,
					isShow: '1',
					deptCode: this.deptCode,
				}).then(res => {
					
					// 将请求结果通过complete传给z-paging处理，同时也代表请求结束，这一行必须调用
					// this.$refs.paging.complete(res.rows);
					this.dataList = res.rows.map(item => {
						if (item.doctorImg) {
							// 替换域名
							let imgurl = item.doctorImg;
							let index = imgurl.indexOf('/profile');
							let urlParts = imgurl.slice(index);
							item.doctorImg = config.baseUrl + urlParts;
							console.log('urlParts==',urlParts)
							console.log('item.doctorImg==',item.doctorImg)
						}
						return item;
					});
					console.log(this.dataList)
					//数据请求完成之后停止下拉刷新
					uni.stopPullDownRefresh();
				});
			}

			// queryList(pageNum, pageSize) {
			// 	// 此处请求仅为演示，请替换为自己项目中的请求
			// 	getDoctorList({
			// 		hospitalCode: this.hospitalCode,
			// 		pageNum: 1,
			// 		pageSize: 1000
			// 	}).then(res => {
			// 		console.log(res)
			// 		// 将请求结果通过complete传给z-paging处理，同时也代表请求结束，这一行必须调用
			// 		// this.$refs.paging.complete(res.rows);
			// 		this.dataList = res.rows
			// 	});
			// }
		}
	}
</script>

<style scoped lang="scss">
	page {
		height: 100%;
		.scroll-view_H {
			width: 100%;
			max-height: calc(100vh - 40rpx);
			background-color: #F6F7F9;
		}

		.work-container {
			width: 100%;
			height: 100%;
			background-color: #F6F7F9;

			.item {
				width: 94%;
				margin-left: 3%;
				padding: 20rpx 20rpx;
				margin-top: 20rpx;
				border-radius: 12rpx;
				background-color: #fff;

				.overEllips {
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
				}

				.avatar {
					width: 120rpx;
					height: 120rpx;
				}
			}

		}

	}
	.noData{
		color: #a0a0a0;
		text-align: center;
		line-height: 45px;
	}
</style>